using System;
using System.Linq;

namespace PingPong.Generic.Helpers
{

	public static class EnumHelper
	{
		/// <summary>
		/// Gets the enum value.
		/// </summary>
		/// <returns>The enum value.</returns>
		/// <param name="value">Value.</param>
		/// <typeparam name="T">The 1st type parameter.</typeparam>
		public static T GetEnumValue<T>(string value)
		{
			var enumType = typeof(T);

			if(!enumType.IsEnum)
			{
				throw new ArgumentException("Can only get enumeration values for defined enumerations.");
			}

			return enumType.GetEnumValues().Cast<T>().Where(val => value.Equals(val.ToString(),StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
		}
	}
}

